import Vue from 'vue';
import VueRouter from 'vue-router';

Vue.use(VueRouter);

// 遍历所有路由 ./ 表示当前目录；true：表示遍历当前目录和子目录的所有.js
const modulesFiles = require.context('./', true, /\.js$/);
const routers = modulesFiles.keys().reduce((routers, modulePath) => {
  if (modulePath !== './index.js') {
    const value = modulesFiles(modulePath);
    routers.push(...value.default);
  }
  return routers;
}, []);


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      meta: { title: '默认首页' },
      redirect: '/canvas/information',
    },
    ...routers,
  ],
});

export default router;
